package edu.nf.takeoutdemo.web.admin;

import edu.nf.takeoutdemo.commons.base.BaseController;
import edu.nf.takeoutdemo.commons.result.PageResult;
import edu.nf.takeoutdemo.commons.result.Result;
import edu.nf.takeoutdemo.model.dto.*;
import edu.nf.takeoutdemo.model.vo.OrderStatisticsVO;
import edu.nf.takeoutdemo.model.vo.OrderVO;
import edu.nf.takeoutdemo.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author zjl
 * @date 2025/11/9
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@RequiredArgsConstructor
@Slf4j
public class OrderController extends BaseController {
    private final OrderService orderService;

    /**
     * 取消订单
     * @param orderCancelDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/cancel")
    public Result<?> cancelOrder(@RequestBody OrderCancelDTO orderCancelDTO) throws Exception{
        orderService.cancelOrder(orderCancelDTO);
        return success();
    }

    /**
     * 接单
     * @param orderConfirmDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/confirm")
    public Result<?> confirmOrder(@RequestBody OrderConfirmDTO orderConfirmDTO){
        orderService.confirmOrder(orderConfirmDTO);
        return success();
    }

    @PutMapping("/rejection")
    public Result<?> rejectionOrder(@RequestBody OrderRejectionDTO orderRejectionDTO) throws Exception {
        orderService.rejectionOrder(orderRejectionDTO);
        return success();
    }

    @PutMapping("/complete/{id}")
    public Result<?> completeOrder(@PathVariable("id") Long id){
        orderService.completeOrder(id);
        return success();
    }

    @PutMapping("/delivery/{id}")
    public Result<?> deliveryOrder(@PathVariable("id")  Long id){
        orderService.deliveryOrder(id);
        return success();
    }

    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrderPageQueryDTO orderPageQueryDTO){
        log.info("orderPageQueryDTO={}", orderPageQueryDTO);
        PageResult pageResult =  orderService.conditionSearch(orderPageQueryDTO);
        return success(pageResult);
    }

    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        return success(orderService.statistics());
    }

    @GetMapping("/details/{id}")
    public Result<OrderVO> getDetails(@PathVariable("id") Long id){
        return success(orderService.getDetails(id));
    }


}
